const { watch,series,src,dest } = require('gulp'); 
const uglify = require('gulp-uglify');
var gutil   = require('gulp-util'); 
var concat  = require('gulp-concat');
// 获取 minify-css 模块（用于压缩 CSS）
const minifyCSS  = require('gulp-minify-css');
const rename = require('gulp-rename');
const statik = require('node-static');
const del = require('delete');
function clean(cb){
    del('dest/js/*.js',cb());
}
function js(cb) {
    // body omitted
    cb();
  }
  
function css(cb) {
    // body omitted
    //src('BJUI/css/*.css')

    cb();
}

function build(cb) {
    src(['BJUI/js/bjui-core.js',
        'BJUI/js/bjui-regional.zh-CN.js',
        'BJUI/js/bjui-frag.js',
        'BJUI/js/bjui-extends.js',
        'BJUI/js/bjui-basedrag.js',
        'BJUI/js/bjui-slidebar.js',
        'BJUI/js/bjui-contextmenu.js',
        'BJUI/js/bjui-navtab.js',
        'BJUI/js/bjui-dialog.js',
        'BJUI/js/bjui-taskbar.js',
        'BJUI/js/bjui-ajax.js',
        'BJUI/js/bjui-alertmsg.js',
        'BJUI/js/bjui-pagination.js',
        'BJUI/js/bjui-util.date.js',
        'BJUI/js/bjui-datepicker.js',
        'BJUI/js/bjui-ajaxtab.js',
        'BJUI/js/bjui-datagrid.js',
        'BJUI/js/bjui-tablefixed.js',
        'BJUI/js/bjui-tabledit.js',
        'BJUI/js/bjui-spinner.js',
        'BJUI/js/bjui-lookup.js',
        'BJUI/js/bjui-tags.js',
        'BJUI/js/bjui-upload.js',
        'BJUI/js/bjui-theme.js',
        'BJUI/js/bjui-initui.js',
        'BJUI/js/bjui-plugins.js'])
    .pipe(concat('bjui-all.js'))
    .pipe(uglify())
    .pipe(rename({suffix:'.min'}))
    .pipe(dest('dest/js')); 
    cb();
}
function serve(){
    watch(['BJUI/js/*.js'], series(build));
    const file = new statik.Server('./');

    require('http').createServer(function (request, response) {
    request.addListener('end', function () {
       
        file.serve(request, response);
    }).resume();
    }).listen(8080);
    console.log('http://localhost:8080')
    // var server = gls.static('/', 8000);
    // server.start();
    // watch(['/**/*.css', '**/*.html', '**/*.js'], function(file) {
    //     server.notify.apply(server, [file]);
    // });
}
exports.build = build;
exports.clean = clean;
exports.serve = serve;
exports.default = series(clean,build);
